<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<meta name="keyword" content="">

    <link rel="shortcut icon" href="/node-mongodb-native/2.2/img/favicon.png">

    <title>Legacy Connection Settings</title>

    <link rel="stylesheet" href="/node-mongodb-native/2.2/lib/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="/node-mongodb-native/2.2/lib/font-awesome/css/font-awesome.min.css" type="text/css" />
<link rel="stylesheet" href="/node-mongodb-native/2.2/css/mongodb-docs.css" type="text/css" />
<link rel="stylesheet" href="/node-mongodb-native/2.2/css/overrides.css" type="text/css" />
<link rel="stylesheet" href="/node-mongodb-native/2.2/lib/highlight/styles/idea.css" />
<link rel="stylesheet" href="/node-mongodb-native/2.2/lib/bootstrap-toggle/bootstrap-toggle.min.css" type="text/css" />
<link rel="stylesheet" href="/node-mongodb-native/2.2/css/java.css" type="text/css" />


  </head>

  <body>
  
  <section id="container" class="">
      
      <header id="header-db" class="row" role="navigation">
  <div class="header-content">
    <div class="toggle-nav pull-left">
        <i class="fa fa-bars"></i>
        <div class="icon-reorder tooltips" data-original-title="Toggle Navigation" data-placement="bottom"></div>
    </div>
    
    <div class="logo pull-left">
      <a href="https://www.mongodb.com/">
        <img src="https://mongodb.github.io/node-mongodb-native/img/logo-mongodb-header.png", alt="MongoDB.com" />
      </a>
    </div>
    
    <div>
<div class="nav-items pull-right">
  <a href="https://university.mongodb.com" data-toggle="tooltip" data-placement="bottom" title="Free Online Classes">MongoDB University</a>
  <a href="https://www.mongodb.com/try" data-toggle="tooltip" data-placement="bottom" title="Download MongoDB">Downloads</a>
  <a href="https://www.mongodb.com/community" data-toggle="tooltip" data-placement="bottom" title="Get involved with MongoDB">Community</a>
  <a href="https://www.mongodb.com/docs" data-toggle="tooltip" data-placement="bottom" title="The MongoDB Documentation">Docs</a>
  <a href="https://www.mongodb.com/blog" data-toggle="tooltip" data-placement="bottom" title="The MongoDB Blog">Blog</a>
  <div id="search">
<form method="get" action="//www.google.com/search" target="_blank">
    <input type="text" name="searchQuery" size="20" value="" autocomplete="off" placeholder="Search docs">
    <input type="hidden" name="site" value="/node-mongodb-native/2.2">
    <input type="hidden" name="q" value="">
    <label for="searchQuery"><i class="fa fa-search fa-1"></i></label>
</form>
</div>

</div>
</div>

  </div>
</header>


      

      
<aside id="sidebar" class="sidebar">
    <div class="ssidebar nav-collapse">
      <div class="ssidebarwrapper">
        <h3>
          <a class="index-link" href="/node-mongodb-native/2.2/../">MongoDB Node.js Driver</a>
          <a class="version pull-right" href="/node-mongodb-native/2.2">2.2</a>
        </h3>

        
        <ul class="sidebar-menu">
          
          
          
          
          
          
          
          
          
          
          
          

          
          
            
            









  


          
            
            









  


          
            
            









  
    
    
      
      
        
        
        
        
        
        
        
        









  
    
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
    
      
    
  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  
    
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
    
      
    
  


        
          
        
      
    
    
      
    
  


          
            
            









  
    
    
      
      
        
        
        
        
        
        
        
        









  
    
    
      
      
        
        
        
        
        
        
        
        









  


        
          
        
      
    
      
      
        
        
        
        
        
        
        
        









  
  
  
  
  
  
  
  

  
    
    
    
      
      
      
        
      
    
    
  
  


        
      
    
    
  


        
      
    
      
      
        
      
    
      
      
    
      
      
    
      
      
    
    
  


          
            
            









  
    
    
      
      
    
    
  


          
            
            









  


          
            
            









  


          
            
            









  


          
            
            









  


          

          

          
            
            
















    <li class="toctree-l1">
    <a href="/node-mongodb-native/2.2/installation-guide/installation-guide/">
        <i class='fa fa-puzzle-piece'></i>
        Installation Guide
    </a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="/node-mongodb-native/2.2/quick-start/quick-start/">
        <i class='fa fa-road'></i>
        Quick Start
    </a>
  </li>


          
            
            
















<li class="toctree-l1 ">
  <a href="/node-mongodb-native/2.2/tutorials/main/" class="">
      <i class='fa fa-thumb-tack'></i>
      <span>Tutorials</span>
      <span class="menu-arrow fa fa-angle-right"></span>
  </a>
    <ul >
        
        
        
        
















<li class="toctree-l2 ">
  <a href="/node-mongodb-native/2.2/tutorials/connect/" class="">
      <i class='fa'></i>
      <span>Connect to MongoDB</span>
      
  </a>
    <ul >
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/tutorials/connect/authenticating/">
        <i class='fa'></i>
        Authentication
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/tutorials/connect/ssl/">
        <i class='fa'></i>
        SSL Settings
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/tutorials/collations/">
        <i class='fa'></i>
        Collations
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/tutorials/collections/">
        <i class='fa'></i>
        Collections
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/tutorials/create-indexes/">
        <i class='fa'></i>
        Create Indexes
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/tutorials/crud/">
        <i class='fa'></i>
        CRUD Operations
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/tutorials/projections/">
        <i class='fa'></i>
        Projections
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/tutorials/aggregation/">
        <i class='fa'></i>
        Aggregation
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/tutorials/text-search/">
        <i class='fa'></i>
        Text Search
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/tutorials/geospatial-search/">
        <i class='fa'></i>
        Geospatial Search
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/tutorials/commands/">
        <i class='fa'></i>
        Database Commands
    </a>
  </li>


        
        
        
        
        
















<li class="toctree-l2 ">
  <a href="/node-mongodb-native/2.2/tutorials/gridfs/" class="">
      <i class='fa'></i>
      <span>GridFS</span>
      
  </a>
    <ul >
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/tutorials/gridfs/streaming/">
        <i class='fa'></i>
        GridFS API
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/tutorials/gridfs/gridstore/">
        <i class='fa'></i>
        Legacy GridStore
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
    </ul>
  </li>


          
            
            













  




<li class="toctree-l1  current">
  <a href="/node-mongodb-native/2.2/reference/main/" class="">
      <i class='fa fa-book'></i>
      <span>Reference</span>
      <span class="menu-arrow fa fa-angle-down"></span>
  </a>
    <ul  class="current">
        
        
        
        













  




<li class="toctree-l2  current">
  <a href="/node-mongodb-native/2.2/reference/connecting/" class="">
      <i class='fa'></i>
      <span>Connection Options</span>
      
  </a>
    <ul  class="current">
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/reference/connecting/connection-settings/">
        <i class='fa'></i>
        Connection Settings
    </a>
  </li>


        
        
        
        
        













  




    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/reference/connecting/legacy-connection-settings/">
        <i class='fa'></i>
        Legacy Connection Settings
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















<li class="toctree-l2 ">
  <a href="/node-mongodb-native/2.2/reference/ecmascript6/" class="">
      <i class='fa'></i>
      <span>ECMAScript 6</span>
      
  </a>
    <ul >
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/reference/ecmascript6/connecting/">
        <i class='fa'></i>
        Connecting
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/reference/ecmascript6/crud/">
        <i class='fa'></i>
        CRUD Operations
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















<li class="toctree-l2 ">
  <a href="/node-mongodb-native/2.2/reference/management/" class="">
      <i class='fa'></i>
      <span>Management</span>
      
  </a>
    <ul >
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/reference/management/logging/">
        <i class='fa'></i>
        Logging
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/reference/management/apm/">
        <i class='fa'></i>
        APM
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="/node-mongodb-native/2.2/reference/management/sdam-monitoring/">
        <i class='fa'></i>
        Topology Monitoring
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/reference/pool/">
        <i class='fa'></i>
        Pool Design
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/reference/faq/">
        <i class='fa'></i>
        Frequently Asked Questions
    </a>
  </li>


        
        
    </ul>
  </li>


          
            
            
















<li class="toctree-l1 ">
  <a href="/node-mongodb-native/2.2/upgrade-migration/main/" class="">
      <i class='fa fa-cog'></i>
      <span>Upgrade Guide</span>
      <span class="menu-arrow fa fa-angle-right"></span>
  </a>
    <ul >
        
        
        
        
















    <li class="toctree-l2">
    <a href="/node-mongodb-native/2.2/upgrade-migration/upgrading/">
        <i class='fa fa-wrench'></i>
        Upgrading to 2.x
    </a>
  </li>


        
        
    </ul>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="/node-mongodb-native/2.2/api">
        <i class='fa fa-file-text-o'></i>
        API Documentation
    </a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="https://github.com/mongodb/node-mongodb-native">
        <i class='fa fa-github'></i>
        Source Code
    </a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="/node-mongodb-native/2.2/issues-help/">
        <i class='fa fa-life-ring'></i>
        Issues &amp; Help
    </a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="https://gitter.im/mongodb/node-mongodb-native?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge">
        <img src='https://badges.gitter.im/Join Chat.svg'/>
        
    </a>
  </li>


          
        </ul>
        
    </div>
  </div>
  
</aside>

<div class="option-popup closed hidden" id="optionsVersionsPopup">
<div class="option-header">
  <i class="fa fa-gear"></i>
  <span>OPTIONS</span>
  <i class="fa fa-angle-up pull-right"></i>
</div>
<div class="option-body">
  <ul>
      
      <li>
        <label>Version</label>
        <div class="btn-group btn-group-xs pull-right">
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            Select Version <span class="caret"></span>
          </button>
          <ul class="dropdown-menu" role="menu" id="optionsVersionsMenu">
          </ul>
        </div>
      </li>

   


    

  </ul>
</div>
</div>



      
      <section id="main-content" class="content">
          <section class="main-column pull-left">
            <div class="document">
              <div class="documentwrapper">
                <div class="bodywrapper">
                  <div class="body">

                    <div class="alert alert-info" role="alert">
  Note: You are currently viewing version 2.2 of the Node.js driver documentation.
  <a href="https://www.mongodb.com/docs/drivers/node">Click here</a> for the latest version.
</div>



   
<a class="edit-link" href="https://github.com/mongodb/node-mongodb-native/blob/2.2/docs/reference/content/reference/connecting/legacy-connection-settings.md" target="_blank" title="Edit reference/connecting/legacy-connection-settings.md on GitHub"><i class="fa fa-pencil-square-o"></i></a>










<div class="bc">
<ul>
  
  
  
  
  <li><a href="/node-mongodb-native/2.2/reference/main/">Reference</a> <i class="fa fa-angle-right"></i></li>
  <li><a href="/node-mongodb-native/2.2/reference/connecting/">Connection Options</a> <i class="fa fa-angle-right"></i></li>
  <li>Legacy Connection Settings</li>
</ul>
</div>




<h1 id="connect-to-mongodb-legacy">Connect To MongoDB (Legacy)</h1>

<div class="admonition note">
<h5 class="admonition-title">Note</h5>
<p>For 2.1.10 or earlier. For newer versions, see <a href="/node-mongodb-native/2.2/reference/connecting/">Connect to MongoDB</a></p>

</div>


<p>Connecting to MongoDB using the driver is primarily done using the <code>MongoClient.connect</code> method and a URI. Let&rsquo;s look at how we connect to a couple of different server topologies.</p>

<h2 id="single-server-connection">Single Server Connection</h2>

<p>We have a single MongoDB server instance running on the port <em>27017</em> Let&rsquo;s connect using the driver and <em>MongoClient.connect</em></p>

<pre><code class="language-js">var MongoClient = require('mongodb').MongoClient
  , assert = require('assert');

// Connection URL
var url = 'mongodb://localhost:27017/myproject';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
  assert.equal(null, err);
  console.log(&quot;Connected correctly to server&quot;);

  db.close();
});
</code></pre>

<p>Let&rsquo;s break down the <code>URI</code> string we passed as the first argument to MongoClient.connect.</p>

<table>
<thead>
<tr>
<th align="left">Parameter</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left"><code>mongodb://</code></td>
<td align="left">is the protocol definition</td>
</tr>

<tr>
<td align="left"><code>localhost:27017</code></td>
<td align="left">is the server we are connecting to</td>
</tr>

<tr>
<td align="left"><code>/myproject</code></td>
<td align="left">is the database we wish to connect to</td>
</tr>
</tbody>
</table>

<h2 id="replicaset-server-connection">Replicaset Server Connection</h2>

<p>We wish to connect to a ReplicaSet consisting of one primary and 1 or more secondaries. To Do this we need to supply the driver with a seedlist of servers and the name of the ReplicaSet we wish to connect to. Let&rsquo;s take a look at a code example.</p>

<pre><code class="language-js">var MongoClient = require('mongodb').MongoClient
  , assert = require('assert');

// Connection URL
var url = 'mongodb://localhost:27017,localhost:27018/myproject?replicaSet=foo';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
  assert.equal(null, err);
  console.log("Connected correctly to server");

  db.close();
});
</code></pre>

<p>Let&rsquo;s break down the <code>URI</code> string.</p>

<table>
<thead>
<tr>
<th align="left">Parameter</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left"><code>mongodb://</code></td>
<td align="left">is the protocol definition</td>
</tr>

<tr>
<td align="left"><code>localhost:27017,localhost:27018</code></td>
<td align="left">is the servers we are connecting to to discover the topology of the ReplicaSet.</td>
</tr>

<tr>
<td align="left"><code>/myproject</code></td>
<td align="left">is the database we wish to connect to</td>
</tr>

<tr>
<td align="left"><code>replicaSet=foo</code></td>
<td align="left">is the name of the ReplicaSet we are connecting to. This ensures we are connecting to the correct Replicaset. <strong>This is a required parameter when using the 2.0 driver</strong></td>
</tr>
</tbody>
</table>

<h2 id="mongos-proxy-connection">Mongos Proxy Connection</h2>

<p>We wish to connect to a set of <code>mongos</code> proxies. Just as in the case of connecting to a ReplicaSet we can provide a seed list of <code>mongos</code> proxies. This allows the driver to perform failover between proxies automatically in case of a proxy process having been shut down. Let&rsquo;s look at an example of code connecting to a set of proxies.</p>

<pre><code class="language-js">var MongoClient = require('mongodb').MongoClient
  , assert = require('assert');

// Connection URL
var url = 'mongodb://localhost:50000,localhost:50001/myproject';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
  assert.equal(null, err);
  console.log(&quot;Connected correctly to server&quot;);

  db.close();
});
</code></pre>

<p>Let&rsquo;s break down the <code>URI</code> string.</p>

<table>
<thead>
<tr>
<th align="left">Parameter</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left"><code>mongodb://</code></td>
<td align="left">is the protocol definition</td>
</tr>

<tr>
<td align="left"><code>localhost:50000,localhost:50001</code></td>
<td align="left">is the <em>mongos</em> proxies we are connecting to.</td>
</tr>

<tr>
<td align="left"><code>/myproject</code></td>
<td align="left">is the database we wish to connect to</td>
</tr>
</tbody>
</table>

<p>Let&rsquo;s break down the <code>URI</code> string.</p>

<table>
<thead>
<tr>
<th align="left">Parameter</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left"><code>mongodb://</code></td>
<td align="left">is the protocol definition</td>
</tr>

<tr>
<td align="left"><code>dave:password</code></td>
<td align="left">is the user name and password for the database</td>
</tr>

<tr>
<td align="left"><code>localhost:27017</code></td>
<td align="left">is the server we are connecting to</td>
</tr>

<tr>
<td align="left"><code>/myproject</code></td>
<td align="left">is the database we wish to connect to</td>
</tr>

<tr>
<td align="left"><code>authSource=admin</code></td>
<td align="left">is the database we wish to authenticate against</td>
</tr>
</tbody>
</table>

<h1 id="mongoclient-connect-optional-parameters">MongoClient.connect Optional Parameters</h1>

<p>The driver has many more options for tweaking than what&rsquo;s available through the <code>URI</code> specification. These can be passed to the driver using an optional parameters object. The top level fields in the options object are.</p>

<table>
<thead>
<tr>
<th align="left">Parameter</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left"><code>db</code></td>
<td align="left">Options that affect the Db instance returned by the MongoClient.connect method.</td>
</tr>

<tr>
<td align="left"><code>replSet</code></td>
<td align="left">Options that modify the Replicaset topology connection behavior. <strong>This is a required parameter when using the 2.0 driver</strong></td>
</tr>

<tr>
<td align="left"><code>mongos</code></td>
<td align="left">Options that modify the Mongos topology connection behavior.</td>
</tr>

<tr>
<td align="left"><code>server</code></td>
<td align="left">Options that modify the Server topology connection behavior.</td>
</tr>
</tbody>
</table>

<p>A simple example connecting to a single server setting all returned queries to be raw BSON buffers and adjusting the poolSize to be 10 connections for this connection.</p>

<pre><code class="language-js">var MongoClient = require('mongodb').MongoClient
  , assert = require('assert');

// Connection URL
var url = 'mongodb://dave:password@localhost:27017/myproject';
// Use connect method to connect to the Server
MongoClient.connect(url, {
    db: {
      raw: true
    },
    server: {
      poolSize: 10
    }
  }, function(err, db) {
  assert.equal(null, err);
  console.log(&quot;Connected correctly to server&quot;);

  db.close();
});
</code></pre>

<p>Let&rsquo;s look at the individual options for each of the top level fields.</p>

<h2 id="data-base-level-options">Data base level options</h2>

<table>
<thead>
<tr>
<th align="left">Parameter</th>
<th align="left">Type</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left"><code>w</code></td>
<td align="left">{Number/String, &gt; -1 || &lsquo;majority&rsquo;}</td>
<td align="left">the write concern for the operation where &lt; 1 is no acknowledgment of write and w &gt;= 1 or w = &lsquo;majority&rsquo; acknowledges the write</td>
</tr>

<tr>
<td align="left"><code>wtimeout</code></td>
<td align="left">{Number, 0}</td>
<td align="left">set the timeout for waiting for write concern to finish (combines with w option)</td>
</tr>

<tr>
<td align="left"><code>fsync</code></td>
<td align="left">(Boolean, default:false)</td>
<td align="left">write waits for fsync before returning</td>
</tr>

<tr>
<td align="left"><code>j</code></td>
<td align="left">(Boolean, default:false)</td>
<td align="left">write waits for journal sync before returning</td>
</tr>

<tr>
<td align="left"><code>readPreference</code></td>
<td align="left">{String}</td>
<td align="left">the preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).</td>
</tr>

<tr>
<td align="left"><code>readPreferenceTags</code></td>
<td align="left">{Object, default:null}</td>
<td align="left">the tags object {&lsquo;loc&rsquo;:&lsquo;ny&rsquo;} used with the readPreference.</td>
</tr>

<tr>
<td align="left"><code>native_parser</code></td>
<td align="left">{Boolean, default:false}</td>
<td align="left">use c++ bson parser.</td>
</tr>

<tr>
<td align="left"><code>forceServerObjectId</code></td>
<td align="left">{Boolean, default:false}</td>
<td align="left">force server to create _id fields instead of client.</td>
</tr>

<tr>
<td align="left"><code>pkFactory</code></td>
<td align="left">{Object}</td>
<td align="left">object overriding the basic ObjectID primary key generation.</td>
</tr>

<tr>
<td align="left"><code>serializeFunctions</code></td>
<td align="left">{Boolean, default:false}</td>
<td align="left">serialize functions.</td>
</tr>

<tr>
<td align="left"><code>raw</code></td>
<td align="left">{Boolean, default:false}</td>
<td align="left">perform operations using raw bson buffers.</td>
</tr>

<tr>
<td align="left"><code>bufferMaxEntries</code></td>
<td align="left">{Number, default: -1}</td>
<td align="left">sets a cap on how many operations the driver will buffer up before giving up on getting a working connection, default is -1 which is unlimited.</td>
</tr>
</tbody>
</table>

<p>If you are connecting to a MongoDB replicaset, you pass the parameters using the <code>replset</code> options field.</p>

<pre><code class="language-js">var MongoClient = require('mongodb').MongoClient,
  f = require('util').format,
  fs = require('fs');

MongoClient.connect(f('mongodb://%s@server:27017/test'), {
  db: {
    w:1
  }
}, function(err, db) {
  db.close();
});

</code></pre>

<h2 id="individual-server-level-options">Individual Server Level Options</h2>

<table>
<thead>
<tr>
<th align="left">Parameter</th>
<th align="left">Type</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left"><code>poolSize</code></td>
<td align="left">{Number, default: 5}</td>
<td align="left">Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons.</td>
</tr>

<tr>
<td align="left"><code>ssl</code></td>
<td align="left">{Boolean, default: false}</td>
<td align="left">Use ssl connection (needs to have a mongod server with ssl support).</td>
</tr>

<tr>
<td align="left"><code>sslValidate</code></td>
<td align="left">{Boolean, default: true}</td>
<td align="left">Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>checkServerIdentity</code></td>
<td align="left">{Boolean|Function, default: true}</td>
<td align="left">Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function.</td>
</tr>

<tr>
<td align="left"><code>sslCA</code></td>
<td align="left">{Buffer[]|string[], default: null}</td>
<td align="left">Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>sslCert</code></td>
<td align="left">{Buffer|string, default: null}</td>
<td align="left">String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>sslKey</code></td>
<td align="left">{Buffer|string, default: null}</td>
<td align="left">String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>sslPass</code></td>
<td align="left">{Buffer|string, default: null}</td>
<td align="left">String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>autoReconnect</code></td>
<td align="left">{Boolean, default: true}</td>
<td align="left">Reconnect on error.</td>
</tr>

<tr>
<td align="left"><code>socketOptions.noDelay</code></td>
<td align="left">{Boolean, default: true}</td>
<td align="left">TCP Socket NoDelay option.</td>
</tr>

<tr>
<td align="left"><code>socketOptions.keepAlive</code></td>
<td align="left">{Number, default: 30000}</td>
<td align="left">The number of milliseconds to wait before initiating keepAlive on the TCP socket.</td>
</tr>

<tr>
<td align="left"><code>socketOptions.connectTimeoutMS</code></td>
<td align="left">{Number, default: 30000}</td>
<td align="left">TCP Connection timeout setting.</td>
</tr>

<tr>
<td align="left"><code>socketOptions.socketTimeoutMS</code></td>
<td align="left">{Number, default: 360000}</td>
<td align="left">TCP Socket timeout setting.</td>
</tr>
</tbody>
</table>

<p>If you are connecting to a single MongoDB instance you pass the parameters using the <code>server</code> options field.</p>

<pre><code class="language-js">var MongoClient = require('mongodb').MongoClient,
  f = require('util').format,
  fs = require('fs');

MongoClient.connect(f('mongodb://%s@server:27017/test'), {
  server: {
      sslKey:key
    , sslCert:cert
  }
}, function(err, db) {
  db.close();
});

</code></pre>

<h2 id="replicaset-level-options">Replicaset Level Options</h2>

<table>
<thead>
<tr>
<th align="left">Parameter</th>
<th align="left">Type</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left"><code>ha</code></td>
<td align="left">{Boolean, default:true}</td>
<td align="left">Controls if the replicaset monitoring runs or not.</td>
</tr>

<tr>
<td align="left"><code>haInterval</code></td>
<td align="left">{Number, default:10000}</td>
<td align="left">The number of milliseconds between each ping of the replicaset members. The replicaset monitoring process, is the process monitoring the replicaset, detecting new members and reconnecting to existing members.</td>
</tr>

<tr>
<td align="left"><code>replicaSet</code></td>
<td align="left">{String}</td>
<td align="left">the name of the replicaset to connect to. <strong>This is a required parameter when using the 2.0 driver</strong></td>
</tr>

<tr>
<td align="left"><code>secondaryAcceptableLatencyMS</code></td>
<td align="left">{Number, default:15}</td>
<td align="left">sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms)</td>
</tr>

<tr>
<td align="left"><code>connectWithNoPrimary</code></td>
<td align="left">{Boolean, default:false}</td>
<td align="left">Sets if the driver should connect even if no primary is available.</td>
</tr>

<tr>
<td align="left"><code>poolSize</code></td>
<td align="left">{Number, default: 5}</td>
<td align="left">Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons.</td>
</tr>

<tr>
<td align="left"><code>ssl</code></td>
<td align="left">{Boolean, default: false}</td>
<td align="left">Use ssl connection (needs to have a mongod server with ssl support).</td>
</tr>

<tr>
<td align="left"><code>sslValidate</code></td>
<td align="left">{Boolean, default: true}</td>
<td align="left">Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>checkServerIdentity</code></td>
<td align="left">{Boolean|Function, default: true}</td>
<td align="left">Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function.</td>
</tr>

<tr>
<td align="left"><code>sslCA</code></td>
<td align="left">{Buffer[]|string[], default: null}</td>
<td align="left">Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>sslCert</code></td>
<td align="left">{Buffer|string, default: null}</td>
<td align="left">String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>sslKey</code></td>
<td align="left">{Buffer|string, default: null}</td>
<td align="left">String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>sslPass</code></td>
<td align="left">{Buffer|string, default: null}</td>
<td align="left">String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>socketOptions.noDelay</code></td>
<td align="left">{Boolean, default: true}</td>
<td align="left">TCP Socket NoDelay option.</td>
</tr>

<tr>
<td align="left"><code>socketOptions.keepAlive</code></td>
<td align="left">{Number, default: 30000}</td>
<td align="left">The number of milliseconds to wait before initiating keepAlive on the TCP socket.</td>
</tr>

<tr>
<td align="left"><code>socketOptions.connectTimeoutMS</code></td>
<td align="left">{Number, default: 30000}</td>
<td align="left">TCP Connection timeout setting.</td>
</tr>

<tr>
<td align="left"><code>socketOptions.socketTimeoutMS</code></td>
<td align="left">{Number, default: 360000}</td>
<td align="left">TCP Socket timeout setting.</td>
</tr>
</tbody>
</table>

<p>If you are connecting to a MongoDB replicaset, you pass the parameters using the <code>replset</code> options field.</p>

<pre><code class="language-js">var MongoClient = require('mongodb').MongoClient,
  f = require('util').format,
  fs = require('fs');

MongoClient.connect(f('mongodb://%s@server:27017/test'), {
  replset: {
      sslKey:key
    , sslCert:cert
  }
}, function(err, db) {
  db.close();
});

</code></pre>

<h2 id="mongos-proxy-level-options">Mongos Proxy Level Options</h2>

<table>
<thead>
<tr>
<th align="left">Parameter</th>
<th align="left">Type</th>
<th align="left">Description</th>
</tr>
</thead>

<tbody>
<tr>
<td align="left"><code>ha</code></td>
<td align="left">{Boolean, default:true}</td>
<td align="left">turn on high availability.</td>
</tr>

<tr>
<td align="left"><code>haInterval</code></td>
<td align="left">{Number, default:5000}</td>
<td align="left">time between each replicaset status check.</td>
</tr>

<tr>
<td align="left"><code>secondaryAcceptableLatencyMS</code></td>
<td align="left">{Number, default:15}</td>
<td align="left">sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms)</td>
</tr>

<tr>
<td align="left"><code>poolSize</code></td>
<td align="left">{Number, default: 5}</td>
<td align="left">Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons.</td>
</tr>

<tr>
<td align="left"><code>ssl</code></td>
<td align="left">{Boolean, default: false}</td>
<td align="left">Use ssl connection (needs to have a mongod server with ssl support).</td>
</tr>

<tr>
<td align="left"><code>sslValidate</code></td>
<td align="left">{Boolean, default: true}</td>
<td align="left">Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>checkServerIdentity</code></td>
<td align="left">{Boolean|Function, default: true}</td>
<td align="left">Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function.</td>
</tr>

<tr>
<td align="left"><code>sslCA</code></td>
<td align="left">{Buffer[]|string[], default: null}</td>
<td align="left">Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>sslCert</code></td>
<td align="left">{Buffer|string, default: null}</td>
<td align="left">String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>sslKey</code></td>
<td align="left">{Buffer|string, default: null}</td>
<td align="left">String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>sslPass</code></td>
<td align="left">{Buffer|string, default: null}</td>
<td align="left">String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher).</td>
</tr>

<tr>
<td align="left"><code>socketOptions.noDelay</code></td>
<td align="left">{Boolean, default: true}</td>
<td align="left">TCP Socket NoDelay option.</td>
</tr>

<tr>
<td align="left"><code>socketOptions.keepAlive</code></td>
<td align="left">{Number, default: 30000}</td>
<td align="left">The number of milliseconds to wait before initiating keepAlive on the TCP socket.</td>
</tr>

<tr>
<td align="left"><code>socketOptions.connectTimeoutMS</code></td>
<td align="left">{Number, default: 30000}</td>
<td align="left">TCP Connection timeout setting.</td>
</tr>

<tr>
<td align="left"><code>socketOptions.socketTimeoutMS</code></td>
<td align="left">{Number, default: 360000}</td>
<td align="left">TCP Socket timeout setting.</td>
</tr>
</tbody>
</table>

<p>If you are connecting to a MongoDB replicaset, you pass the parameters using the <code>mongos</code> options field.</p>

<pre><code class="language-js">var MongoClient = require('mongodb').MongoClient,
  f = require('util').format,
  fs = require('fs');

MongoClient.connect(f('mongodb://%s@server:27017/test'), {
  mongos: {
      sslKey:key
    , sslCert:cert
  }
}, function(err, db) {
  db.close();
});

</code></pre>






<div id="btnv">
  
  <div class="pull-left">
  <a class="navigation prev" href="/node-mongodb-native/2.2/reference/connecting/connection-settings/">
      <i class="fa fa-long-arrow-left"> </i> Connection Settings
  </a>
  </div>
  
  
  <div class="pull-right">
  <a class="navigation next" href="/node-mongodb-native/2.2/reference/ecmascript6/">
    ECMAScript 6 <i class="fa fa-long-arrow-right"> </i>
  </a>
  
</div>
</div>


</div>
<div class="right-column">
<div class="wrapper">
  
  <div class="toc">
    <span class="toc-header">On this page</span>
    <nav id="TableOfContents">
<ul>
<li><a href="#connect-to-mongodb-legacy">Connect To MongoDB (Legacy)</a>
<ul>
<li><a href="#single-server-connection">Single Server Connection</a></li>
<li><a href="#replicaset-server-connection">Replicaset Server Connection</a></li>
<li><a href="#mongos-proxy-connection">Mongos Proxy Connection</a></li>
</ul></li>
<li><a href="#mongoclient-connect-optional-parameters">MongoClient.connect Optional Parameters</a>
<ul>
<li><a href="#data-base-level-options">Data base level options</a></li>
<li><a href="#individual-server-level-options">Individual Server Level Options</a></li>
<li><a href="#replicaset-level-options">Replicaset Level Options</a></li>
<li><a href="#mongos-proxy-level-options">Mongos Proxy Level Options</a></li>
</ul></li>
</ul>
</nav>
  </div>
  
</div>
</div>

</div>
</div>
</div>
</section>
</section>

</section>


<script type="text/javascript">
  var DOCUMENTATION_OPTIONS = {
   URL_ROOT:    "/node-mongodb-native/2.2",
   VERSION:     "2.2",
   COLLAPSE_INDEX: false,
   FILE_SUFFIX: '.html',
   HAS_SOURCE:  true
  };
</script>
<script type="text/javascript" src="/node-mongodb-native/2.2/js/jquery.js"></script>
<script type="text/javascript" src="/node-mongodb-native/2.2/lib/bootstrap.js"></script>
<script type="text/javascript" src="/node-mongodb-native/2.2/js/navbar.js"></script>
<script type="text/javascript" src="/node-mongodb-native/2.2/lib/highlight/highlight.pack.js"></script>
<script type="text/javascript" src="/node-mongodb-native/2.2/js/scripts.js"></script>
<script type="text/javascript" src="/node-mongodb-native/2.2/lib/bootstrap-toggle/bootstrap-toggle.min.js"></script>
<script type="text/javascript" src="/node-mongodb-native/2.2/js/java.js"></script>
<script type="text/javascript" src="/node-mongodb-native/2.2/js/toggle-switch.js"></script>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-29229787-1', 'auto');
  ga('send', 'pageview');
</script>
</body>
</html>

